package com.ruoyi.project.modules.role.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.project.modules.usage.mapper.UsageParticipateRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.modules.role.mapper.ParticipateRoleMapper;
import com.ruoyi.project.modules.role.domain.ParticipateRole;
import com.ruoyi.project.modules.role.service.IParticipateRoleService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 参与角色Service业务层处理
 * 
 * @author smallrain
 * @date 2021-11-04
 */
@Service
public class ParticipateRoleServiceImpl implements IParticipateRoleService 
{
    @Autowired
    private ParticipateRoleMapper participateRoleMapper;

    /**
     * 查询参与角色
     * 
     * @param id 参与角色主键
     * @return 参与角色
     */
    @Override
    public ParticipateRole selectParticipateRoleById(Long id)
    {
        return participateRoleMapper.selectParticipateRoleById(id);
    }

    /**
     * 查询参与角色列表
     * 
     * @param participateRole 参与角色
     * @return 参与角色
     */
    @Override
    public List<ParticipateRole> selectParticipateRoleList(ParticipateRole participateRole)
    {
        return participateRoleMapper.selectParticipateRoleList(participateRole);
    }

    /**
     * 新增参与角色
     * 
     * @param participateRole 参与角色
     * @return 结果
     */
    @Override
    public int insertParticipateRole(ParticipateRole participateRole)
    {
        participateRole.setCreateTime(DateUtils.getNowDate());
        participateRole.setCreateBy(ShiroUtils.getLoginName());
        return participateRoleMapper.insertParticipateRole(participateRole);
    }

    /**
     * 修改参与角色
     * 
     * @param participateRole 参与角色
     * @return 结果
     */
    @Override
    public int updateParticipateRole(ParticipateRole participateRole)
    {
        participateRole.setUpdateTime(DateUtils.getNowDate());
        participateRole.setUpdateBy(ShiroUtils.getLoginName());
        return participateRoleMapper.updateParticipateRole(participateRole);
    }

    @Resource
    private UsageParticipateRoleMapper usageParticipateRoleMapper;

    /**
     * 批量删除参与角色
     * 
     * @param ids 需要删除的参与角色主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteParticipateRoleByIds(String ids)
    {
        usageParticipateRoleMapper.removeByRoleId(Convert.toLongList(ids));
        return participateRoleMapper.deleteParticipateRoleByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除参与角色信息
     * 
     * @param id 参与角色主键
     * @return 结果
     */
    @Override
    public int deleteParticipateRoleById(Long id)
    {
        return participateRoleMapper.deleteParticipateRoleById(id);
    }

    @Override
    public List<ParticipateRole> selectParticipateRoleListByUsageId(Long usageId) {
        return participateRoleMapper.selectParticipateRoleListByUsageId(usageId);
    }
}
